#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
    key_t mykey;
    if((mykey = ftok(".",100)) == -1)
    {
        perror("fail to ftok");
        exit(-1);
    }

    int shm = 0;
    if((shm = shmget(mykey,500,IPC_CREAT|0666)) == -1)
    {
        perror("fail to shmget");
        exit(-1);
    }

    char *text;
    if((text = shmat(shm,NULL,0)) == (void *)-1)
    {
        perror("fail to shmat");
        exit(-1);
    }
    printf("text = %s",text);

    if(shmdt(text) == -1)
    {
        perror("fail to shmdt");
        exit(-1);
    }
    return 0;
}